﻿@model LoginModel

@using SmartStore.Web.Models.Customer;
@using SmartStore.Core;
@using SmartStore.Core.Infrastructure;
@using SmartStore.Core.Domain.Customers;

@{
    Layout = "_Layout";

    Html.AddTitleParts(T("PageTitle.Login").Text);

    var registerUrl = Url.RouteUrl("Register");
    if (!String.IsNullOrEmpty(this.Context.Request.QueryString["returnUrl"]))
    {
        var webHelper = EngineContext.Current.Resolve<IWebHelper>();
        registerUrl = webHelper.ModifyQueryString(registerUrl, "returnUrl=" + HttpUtility.UrlEncode(this.Context.Request.QueryString["returnUrl"]), null);
    }

    Html.AddCustomHeadParts("<meta name=\"robots\" content=\"noindex\">");
}

<div class="page login-page">
	<div class="page-title">
		<h1>@T("Account.Login.Welcome")</h1>
	</div>

	<div class="row mt-4">
		<div class="col-12 col-md-7 col-lg-6 col-xl-5 order-md-last">
			<div class="card shadow-sm p-4 mb-5 mb-md-0 login-box">
				<h3 class="h4 mb-0">
					@T("Account.Login.ReturningCustomer")
				</h3>
				<hr />
				@if (!ViewData.ModelState.IsValid)
				{
					@Html.ValidationSummary(true, T("Account.Login.Unsuccessful").Text, new { @class = "alert alert-danger" })
				}

				<!-- SignIn Form -->
                <form action="@ViewContext.HttpContext.Request.RawUrl" method="post">
                    @if (Model.CustomerLoginType == CustomerLoginType.Username)
                    {
                        <div class="form-group">
                            <div class="input-group input-group-lg has-icon">
                                @Html.TextBoxFor(m => m.Username, new { @class = "username form-control", placeholder = Html.DisplayNameFor(m => m.Username) })
                                <span class="input-group-icon text-muted">
                                    <i class="icm icm-user"></i>
                                </span>
                            </div>
                            @Html.ValidationMessageFor(m => m.Username)
                        </div>
                    }
                    else if (Model.CustomerLoginType == CustomerLoginType.Email)
                    {
                        <div class="form-group">
                            <div class="input-group input-group-lg has-icon">
                                @Html.TextBoxFor(m => m.Email, new { @class = "email form-control", type = "email", placeholder = Html.DisplayNameFor(m => m.Email) })
                                <span class="input-group-icon text-muted">
                                    <i class="icm icm-envelope-open"></i>
                                </span>
                            </div>
                            @Html.ValidationMessageFor(m => m.Email)
                        </div>
                    }
                    else
                    {
                        <div class="form-group">
                            <div class="input-group input-group-lg has-icon">
                                @Html.TextBoxFor(m => m.UsernameOrEmail, new { @class = "username form-control", placeholder = Html.DisplayNameFor(m => m.UsernameOrEmail) })
                                <span class="input-group-icon text-muted">
                                    <i class="icm icm-user"></i>
                                </span>
                            </div>
                            @Html.ValidationMessageFor(m => m.UsernameOrEmail)
                        </div>
                    }

                    <div class="form-group">
                        <div class="input-group input-group-lg has-icon">
                            <input type="password" class="password form-control" autocomplete="off"
                                   placeholder="@Html.DisplayNameFor(m => m.Password)"
                                   id="@Html.FieldIdFor(m => m.Password)"
                                   name="@Html.FieldNameFor(m => m.Password)"
                                   value="@(Model.Password.HasValue() ? Model.Password : null)" />
                            <span class="input-group-icon text-muted">
                                <i class="icm icm-shield"></i>
                            </span>
                        </div>
                        @Html.ValidationMessageFor(m => m.Password)
                    </div>

                    <div class="form-group d-flex justify-content-between">
                        <div class="form-check">
                            @Html.CheckBoxFor(m => m.RememberMe, new { @class = "form-check-input" })
                            <label for="@Html.IdFor(m => m.RememberMe)" class="form-check-label">@T("Account.Login.Fields.RememberMe")</label>
                        </div>
                        <div class="forgot-password">
                            @Html.ActionLink(T("Account.Login.ForgotPassword").Text, "PasswordRecovery", "Customer")
                        </div>
                    </div>

                    @if (Model.DisplayCaptcha)
                    {
                        <div class="form-group captcha-box">
                            @Html.Raw(Html.GenerateCaptcha())
                        </div>
                    }

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary btn-lg btn-block btn-login">
                            @T("Account.Login.LoginButton")
                        </button>
                    </div>

                    @{ Html.RenderAction("ExternalMethods", "ExternalAuthentication"); }
                </form>
			</div>
		</div>
		<div class="col-12 col-md-5 col-lg-6 col-xl-7 order-md-first">
			<div class="page-info">
				@{
					Html.RenderPartial("_ExternalAuthentication.AssociateMessage");
					Html.RenderAction("TopicBlock", "Topic", new { systemName = "LoginRegistrationInfo", bodyOnly = true, isLead = true });
				}
			</div>

			<div class="register-block">
				@if (Model.CheckoutAsGuest)
				{
					Html.RenderAction("TopicBlock", "Topic", new { systemName = "CheckoutAsGuestOrRegister", bodyOnly = true });
					<div class="row sm-gutters">
						<div class="col-sm-6 col-md-12 col-lg-6 pb-2 pb-lg-0">
							<a class="btn btn-warning btn-lg btn-block register-button" href="@registerUrl">
								@T("Account.Register.Button")
							</a>
						</div>
						<div class="col-sm-6 col-md-12 col-lg-6">
							<a class="btn btn-secondary btn-lg btn-block checkout-as-guest-button" href="@Url.RouteUrl("Checkout")">
								<span>@T("Account.Login.CheckoutAsGuest")</span>
								<i class="fa fa-angle-right"></i>
							</a>
						</div>
					</div>
				}
				else
				{
					<div class="row">
						<div class="col-12 col-lg-auto">
							<a class="btn btn-warning btn-lg btn-block register-button" href="@registerUrl">
								@T("Account.Register.Button")
							</a>
						</div>
					</div>
				}
			</div>
		</div>
	</div>
</div>